// pages/index/index.js
const app = getApp()
import formatimestamp from '../../utils/formatStamp'
import {averageUser, dealers} from '../../utils/tabbar/tabbarUrl'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pages: [
      {id: 1, name: '移动元素', path: '/pages/move-box/index'},
      {id: 2, name: '拖动及缩放功能实现', path: '/pages/move-box-scale/index'},
      {id: 3, name: 'arrayBuffer转图片', path: '/pages/arraybuffer2img/index'},
      {id: 4, name: '滑动的nav-bar', path: '/pages/my-nav-bar/index'},
      {id: 5, name: '自定义标题栏', path: '/pages/my-custom-nav-bar/index'},
      {id: 6, name: '自定义底部导航栏', path: '/pages/my-custom-tab-bar-role/index'},
      {id: 7, name: '分包及图片预览缩放移动', path: '/pages/my-sub-package/index'},
      {id: 8, name: '小程序长按二维码识别', path: '/pages/longpress-image-scan/index'},
      {id: 9, name: '代码共享behavior的使用', path: '/pages/my-behavior/index'},
      {id: 10, name: '自定义步骤条', path: '/pages/zxm-steps/index'},
      {id: 11, name: '小程序中使用echarts', path: '/pages/zxm-echart/index'},
      {id: 12, name: '小程序中css实现动画加载', path: '/pages/loading-style/index'},
      {id: 13, name: '小程序分页列表离开后返回原位置', path: '/pages/list-page/index'},
      {id: 13, name: '小程序分页列表离开后返回原位置传页码', path: '/pages/list-page-scroll/index'},
      {id: 14, name: '小程序低功耗蓝牙的使用', path: '/pages/bluetooth/index'},
      {id: 15, name: '小程序组件监听器--计算属性及监听字段', path: '/pages/cpn-observers/index'},
      {id: 16, name: '小程序适配ios底部小黑条安全区域', path: '/pages/safe-area-ios/index'},
      {id: 17, name: '语音合成-文字播报', path: '/pages/texttvoice/index'},
      {id: 18, name: '语音转文字', path: '/pages/voice2text/index'},
      {id: 19, name: '文本翻译', path: '/pages/texttranslate/index'},
      {id: 20, name: '语音转文字2', path: '/pages/voice2textorigin/index'},
      {id: 21, name: '拍照', path: '/pages/takephoto/index'},
      {id: 22, name: '扫描', path: '/pages/scanphoto/index'},
      {id: 23, name: '滑动的nav-bar联动', path: '/pages/nav-tabs-scroll/index'},
      {id: 24, name: '语音识别', path: '/pages/voice2text-re/index'},
      {id: 25, name: '语音识别对话形式', path: '/pages/voice2textdialog/index'},
      {id: 26, name: '页面间事件通信通道', path: '/pages/event-channel/index'},
      {id: 27, name: '页面间事件通信通道(多页面)', path: '/pages/event-channel-more3page/A'},
      {id: 28, name: '图片处理', path: '/image_load/pages/index/index'},
      {id: 29, name: '小程序录音及播放实现', path: '/pages/recorder/index'},
      {id: 30, name: '小程序消息订阅', path: '/pages/subscribe-message/index'},
      {id: 40, name: '小程序日周月', path: '/pages/zxm-calendar/index'},
      {id: 31, name: '小程序折叠滚动日历', path: '/pages/fold-calendar/index'},
      {id: 32, name: '条纹背景进度条（含动画）', path: '/pages/stripe-progress-bar/index'},
      {id: 33, name: '选择文件不同方式及上传进度监听', path: '/pages/upload-progress-listening/index'},
      {id: 34, name: '媒体资源获取分辨率', path: '/pages/media-pixel/index'},
      {id: 35, name: '海报', path: '/pages/poster-img/index'},
      {id: 36, name: '使用工具生成海报', path: '/pages/poster-img-painter/index'},
      {id: 36, name: '公众号自动回复', path: '/pages/auto-reply-official-account/index'},
      {id: 37, name: '仿淘宝点击tab滑动到对应位置，滑动tab高亮', path: '/pages/tab-scroll-view/index'},
      {id: 38, name: '点击tab滑动到对应位置，滑动tab高亮（tab滑动），', path: '/pages/tab2-scroll-view/index'},
      {id: 39, name: '仿美团左tab右内容，点击滑动，滑动高亮', path: '/pages/tab3-scroll-view/index'},
  ],
    role: 'admin'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: '移动相关',
    })
  },

  toPage(e){
    const { path, name } = e.currentTarget.dataset
    if(path === '/pages/my-custom-tab-bar-home/index'){
      app.globalData.tabbarList = this.data.role === 'admin' ? averageUser : dealers
      wx.switchTab({
        url: '/pages/my-custom-tab-bar-home/index',
      })
      return
    }
    wx.navigateTo({
      url: path + '?name=' + name,
    }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // getTime() 转换为时间戳    
    // toISOString()  方法将日期值转换为ISO 8601格式的字符串    会丢失时区，如果转换日期的需求包含时分秒的话，因为在中国时区，所有得到的结果都会少8个小时
    // 1. ISO 8601: 这是一 种国际标准的日期和时间表示方式，格式为YYYY-MM-DDTHH:mm:ss.sssZ,
    // 其中YYYY代表四位数年份，MM代表月份，DD代表天数，T作为日期和时间的分隔符，HH代表小时，mm代表分钟，ss sss秒和毫秒，Z代表时区。例如: 2023-04-13T15:30:0000Z
    // substring(0, 19)  截取年月日时分秒
    console.log(new Date(new Date().getTime() + 8*3600*1000).toISOString().substring(0, 19));
    console.log(formatimestamp('Y-m-d H:i:s', new Date().getTime()));
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})